package main.iwith;

import main.util.StringUtil;
import net.sf.json.JSONObject;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.Map;

public class ForAnligla {


	public static String getItemName(String str){
		if(StringUtil.isEmpty(str)){
			return null;
		}
		
		int start=str.indexOf("name:");
		
		int end=str.indexOf("type:");
		
		if(start>-1 && end>0){
			return str.substring(start+5, end).trim();
		}
		
		return str;
	}
	
	public static String getIntends(String sentence){
		if(sentence.indexOf("=")<0){
			return null;
		}
		String[] text=sentence.split("=");
		return text[1];
	}
	
	
	public static void fillRow(Sheet sheet,Map<String,Object> intend,int rowNum,String name,String intends){

		String inN=intend.get("intentName").toString();


		//     成功
		if(intends.indexOf(inN)>-1){
			Operator.SUCESS++;
		}else {
			Operator.FAIL++;
			System.out.println("------result:false name:"+name);
			// 彻底失败
			if("Default Fallback Intent".indexOf(inN) > -1){
				Operator.STR += (name + ",");
			}else{
				Row row=sheet.createRow(rowNum);
				Cell cell3=row.createCell(3);
				Operator.NUM++;
				cell3.setCellValue(false);
				// 识别错误
				Cell cell=row.createCell(0);
				cell.setCellValue(name);

				Cell cell1=row.createCell(1);
				cell1.setCellValue(inN);

				Cell cell2=row.createCell(2);
				cell2.setCellValue(intends);

				Cell cell4=row.createCell(4);
				cell4.setCellValue(JSONObject.fromObject(intend.get("parameters")).toString());

				Cell cell5=row.createCell(5);
				cell5.setCellValue(intend.get("time").toString());
			}
		}

	}


	public static void main(String[] args) {
		System.out.print(getItemName("name:bango酸奶冰淇淋	type:菜名	entity:2	alias:"));
	}
}
